<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/25 0025
 * Time: 9:02
 */

namespace Cohuna\Services;


use Cohuna\Models\CohunaMerchant;

class CohunaMerchantService extends ServiceBase
{
    /**
     * 判断指定的商户是否存在
     * @param string $mch_id
     * @return bool
     */
    public function exist($mch_id)
    {
        //$phql = "SELECT id FROM Cohuna\Models\CohunaMerchant WHERE merchant_id = :merchant_id: LIMIT 1";

        //$result = $this->modelsManager->executeQuery($phql,array('merchant_id'=>$mch_id));

        $result = $this->modelsManager->createBuilder()
            ->from('Cohuna\Models\CohunaMerchant')
            ->columns(array('id'))
            ->where('merchant_id = :merchant_id: AND is_delete = 0',array('merchant_id'=>$mch_id))
            ->limit(1)
            ->getQuery()
            ->getSingleResult();

        return isset($result->id) && $result->id > 0;
    }
}